#!/usr/bin/perl
# Version 0.2.1

$testcase = "maxage_flood";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$success = 1;
$state = 0;

open(DUMPFILE, $dumpfile) or $success = 0;

if($success eq 1) {
	while(<DUMPFILE>) {
		
		@l = split(/ /, $_);
		
		# now look at the time
		@ti = split(/\./, $l[0]);
		@ts = split(/:/, $ti[0]);
			
		$secs = $ts[2] + ($ts[1] + $ts[0] * 60) * 60; # secs contains the sim time in seconds
			
		if($state eq 0) {	
			# after approx. 1 hour, we look at the packets in the dump
			if( $secs > 3500) {
				$state = 1;
			}
		}
		if($state eq 1) {
			# look or a max-age update for 0.0.0.1
			if(/0\.0\.0\.(.*) > (.*) OSPFv2-ls_upd (.*) age 3600 rtr 0\.0\.0.1/) {
				$state = 2;
			}
		}
	}

	close(DUMPFILE);
	
	if($state eq 2) {
		$verdict = 1;
		print("TR2's lsa is max-aged by RUT. Test PASSED.\n");
	} elsif($state eq 1) {
		$verdict = 2;
		print("TR2's lsa is not max-aged by RUT. Test FAILED.\n");	
	} 
	
}

if($verdict eq 3) {
	print("Cannot evaluate results. Test INCONCLUSIVE.\n");	
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");